<?php
$page_title = 'eTAT: Add Group';
$style = 'addgroup';
$script = 'addgroup';
require_once 'controller.php';
if(isset($params->x)) {
        $body = '';
        for($c=1; $c<=$params->x; $c++) {
                $body .= "<div id='student$c'><span>$c. </span>";
                $body .= newText('full_name'.$c,'Full Name',array('class'=>'visible','style'=>'width:450px;'));
                $body .= newText('gmail'.$c,'Gmail Address',array('class'=>'visible','style'=>'width:450px;'));
                $body .= "</div>";
        }
        die($body);
}
if(isset($params->c)) {
        $course = $instructor->getCourse($params->c);
} else {
        redirect('myetat.php');
}
if(isset($_POST['add_group_submit'])) {
        $data->group_name = $_POST['group_name'];
        $data->group_description = $_POST['group_description'];
        $data->google_code = $_POST['google_code'];
        $data->google_groups = $_POST['google_groups'];
        if(isset($_POST['student_count'])) {
                $count = $_POST['student_count'];
                for($i=1; $i<=$count; $i++) {
                        $full_name = $_POST["full_name$i"];
                        $gmail = $_POST["gmail$i"];
                        $group_name = $_SESSION['add_project']->group_name;
                        if($full_name != '' || $gmail != '')
                                $students[] = (object) array('full_name'=>$full_name,'gmail'=>$gmail,'group'=>$group_name,'course'=>$course->id);
                }
        }
        $data->students = $students;
        $course->addGroup($data);
        redirect("course.php?c=$course->id");
}
require_once 'header.php';
?>
<div id="mainbody">
	<div class="bodycontent">
    <?php print anchor('/myetat.php','Home').' > '.anchor("course.php?c=$course->id",$course->title).' > '. 'Add Group' ?>
    <div class="rightbar">
    	<div class="tabst2"><span class="txt2">Groups</span></div>
        <div class="right"><?php print "<a href='addgroup.php?c=$course->id'>Add Group</a>";?></div>
		<?php
        if(isset($groups)) {
                foreach($groups as $g) {
                        print "<div id='$g->id-details'>";
                        print "<a href='group.php?g=$g->id'>$g->name</a>";
                        //print counts($g);
//                    	 print "<li>SVN Commits: {$g->getSVNCount()}</li>
//                              <li>Wiki Updates: {$g->getWikiCount()}</li>
//                              <li>Forum Posts: {$g->getForumCount()}</li>
//                              <li>Files: {$g->getFileCount()}</li>
//                              <li>Issue Tracker Updates: {$g->getIssueCount()}</li>";
                        print '</div>';
                }
        } else {
        ?>
       <div id='update-msg'><p>Looks like you haven't added any groups for monitoring, yet.Let's get started by pressing the <b>Add Group</b> button below:</p>
        </div>
    <?php
    }
   // print newBtn('add_group','Add Group',array('type'=>'button','onclick'=>'redirect("addgroup.php?c='.$course->id.'");'));
    ?>
    </div> <!--End of right bar-->
    <div class="main">
    <div class="titletxt"><?php print $course->title; ?>: Add Group</div>

                <?php
                    $form = new Form('final_form','post');
                    $form->textInput('group_name','Group Name',array('required'=>true, 'style'=>'width:450px;'), true);
                    $form->textInput('google_code','Google Code URL',array('required'=>true,'style'=>'width:450px;'),false);
                    $form->button('check_google_code','Check',array('type'=>'button','onclick'=>'checkGoogleCode();'),false);
                    //$form->text("<div class='clear'></div>");
				    $form->text("<div>");
                    $form->textInput('google_groups','Google Groups URL',array('required'=>true,'style'=>'width:450px;'),false);
                    $form->button('check_google_groups','Check',array('type'=>'button','onclick'=>'checkGoogleGroups();'),false);
					$form->text("</div>");
					$form->textArea('group_description','Group Description',3,55,array('style'=>'width:450px;'),true);
                    $form->text("<div class='clear'></div>");
                    $form->textInput('student_count','Enter number of students',array('size'=>'10','maxlength'=>'3'),false);
                    $form->button('student_count_submit','Add',array('type'=>'button'),false);
                    $form->text("<div id='students'></div>");

					$form->text("<div class='centered'>");
					$form->text("<div class='clear'></div>");
                    $form->button('add_group_cancel','Cancel',array('type'=>'button','onclick'=>"redirect('course.php?c=$course->id')",'class'=>'centered'),false);
					$form->button('add_group_submit','Add this group',array('class'=>'centered'),false);
					$form->text("</div>");
                    print $form->build();
                    $check_confirm = newBtn('check_confirm','Yes, this is correct',array('type'=>'button','onclick'=>'closePopup();'),false);
                    $check_cancel = newBtn('check_cancel','No, search again',array('type'=>'button','onclick'=>'closePopup();'),false);
                    $check_body = "
                            <div id='check-output'></div>
                            <div id='row-check-confirm' style='padding:10px;'>
                            $check_confirm $check_cancel
                            </div>";
                    print popup('check-frame',$check_body,900,array('top'=>90,'left'=>40,'padding'=>0));
            ?>

 	  </div>
</div>
<div class='clear'></div>
<?php require_once 'footer.php'; ?>
